# Contributor: Alex Denes <caskd@redxen.eu>
# Maintainer: Alex Denes <caskd@redxen.eu>
pkgname=prometheus-postgres-exporter
_pkgname=postgres_exporter
pkgver=0.14.0
pkgrel=0
pkgdesc="Prometheus exporter for PostgreSQL database"
url="https://github.com/prometheus-community/postgres_exporter"
license="Apache-2.0"
arch="all !riscv64" # nonexistent riscv64 dependency downloaded at build time
makedepends="go>=1.14 bash sed"
install="$pkgname.pre-install $pkgname.pre-upgrade"
subpackages="$pkgname-openrc $pkgname-doc"
source="$_pkgname-$pkgver.tar.gz::https://github.com/prometheus-community/postgres_exporter/archive/v$pkgver.tar.gz
	postgres-exporter.initd
	postgres-exporter.confd
	disable-go-race-detector.patch
	README.Alpine"
builddir="$srcdir/$_pkgname-$pkgver"

case "$CARCH" in
# overflowing int value
x86|arm*) options="$options !check" ;;
esac

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	make build
}

check() {
	make test
}

package() {
	install -Dm755 postgres_exporter "$pkgdir"/usr/bin/postgres_exporter

	install -Dm755 "$srcdir"/postgres-exporter.initd "$pkgdir"/etc/init.d/postgres-exporter
	install -Dm644 "$srcdir"/postgres-exporter.confd "$pkgdir"/etc/conf.d/postgres-exporter
	install -Dm644 "$srcdir"/README.Alpine "$pkgdir"/usr/share/doc/postgres-exporter/README.Alpine
}

sha512sums="
47a0aa844512d0a3d7853253ef9382ebb51514e02566bbac479cea0c5f20a4f03889fe56ff9cb37a85d75c18d5241764ec1113961759affdd07ae6f6b8152ce3  postgres_exporter-0.14.0.tar.gz
e083183953fee8976765a872b7e21b859a4d907ef650e0320e63da4eff388b6c7f63c82a75cbd14e8f78e06018bae6d67666ebf2451adcbe7261e30f3889125f  postgres-exporter.initd
14646244988a670caa12eb6cb5e8bea7259c27ec5fe8d89ee6f73675348a66fdfec68cc06304fcf1ce637737c3be7c38e25824e6efe302ed99ced73021d045c3  postgres-exporter.confd
0e916a9216fbf21865a3672a1159836993048de1112dc8ddbd4e8283264d7fe12c5a5e2b08adeced2db6d4d35feb799c59eae7e55d010d045e825b4a524ae5e2  disable-go-race-detector.patch
d4d8131a2d4787a50f4376cda01f52cc4d40e41088342db7a559e58d464fc92e3110bed542f8622259dd45990e1a95a73806310e1f80c212065e265181e22b32  README.Alpine
"
